<template>
    <div class="createQuestion">
      <header>添加标签</header>
      <div class="content">
        <div class="tags_title">已有标签</div>
        <div class="hadTags">
          <div class="tags" v-for="(item,index) in hadTagList">
            {{item}}
            <label class="closeTab" @click="deleteTab(index)">-</label>
          </div>
        </div>
        <div class="addTagDiv">
          <div class="tags_title">创建新的标签</div>
          <div class="inputDive">
            <div class="input">
              <el-input v-model="input" placeholder="请输入内容"></el-input>
            </div>
            <el-button @click="addTab">添加</el-button>
          </div>
        </div>
      </div>
      <footer>
        <div class="buttons but1" @click="close">取消</div>
        <div class="buttons but2" @click="addQuestion">确认</div>
      </footer>
    </div>
</template>

<script>
  import {mapActions} from 'vuex'
  export default {
    props:['tags'],
    name: "chooseTabs",
    data() {
      return {
        hadTagList:[], //已选标签
        input:'',
      }
    },
    created() {
      let self = this
      for (let i = 0; i < self.tags.length; i++){
        self.hadTagList.push(self.tags[i])
      }
    },
    mounted() {
    },
    methods: {
      ...mapActions([
        'upstate'
      ]),
      //删除已选标签
      deleteTab(index){
        let self = this
        self.hadTagList.splice(index,1)
      },
      //添加标签
      addTab(){
        let self = this
        if (self.input != ''){
          self.hadTagList.push(self.input)
          self.input = ''
        } else {
          this.$notify({
            title: '警告',
            message: '标签不能为空',
            type: 'warning'
          });
        }
      },
      //取消
      close(){
        let self = this
        self.upstate({key:'showchooseTabs',val:false})
      },
      //确定
      addQuestion(){
        let self = this
        self.upstate({key:'showchooseTabs',val:false})
        this.$emit('chooseBack',self.hadTagList);
      },
    }
  }
</script>

<style lang="less">
  .createQuestion{
    width: 660px;
    height: 100%;
    background: #fff;
    border-left: 1px solid #e5e5e5;
    box-shadow: #eeeeee 0px 0px 15px;
    position: absolute;
    right: 0;
    top: 0;
    z-index: 9;
    header{
      width: 100%;
      height: 74px;
      line-height: 74px;
      border-bottom: 1px solid #e5e5e5;
      padding: 0 30px;
      box-sizing: border-box;
      font-size: 20px;
      color: #222222;
    }
    .content{
      width: 100%;
      display: flex;
      flex-direction: column;
      padding: 32px 28px;
      box-sizing: border-box;
      .tags_title{
        font-size: 14px;
        line-height: 14px;
        color: #666666;
        margin-bottom: 18px;
        font-weight: 500;
      }
      .hadTags{
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        padding-bottom: 8px;
        border-bottom: 1px dashed #e5e5e5;
        .tags{
          height: 38px;
          padding: 0 18px;
          border: 1px solid #dddddd;
          font-size: 18px;
          line-height: 38px;
          text-align: center;
          color: #555555;
          position: relative;
          margin-right: 10px;
          margin-bottom: 10px;
          .closeTab{
            width: 14px;
            height: 14px;
            border-radius: 50%;
            background: #e85151;
            text-align: center;
            line-height: 12px;
            position: absolute;
            top: -5px;
            right: -5px;
            color: #fff;
            font-size: 16px;
            cursor: pointer;
          }
        }
      }
      .addTagDiv{
        padding-top: 32px;
        display: flex;
        flex-direction: column;
        .inputDive{
          display: flex;
          flex-direction: row;
          width: 100%;
          .input{
            width: 80%;
            margin-right: 5px;
          }
        }
      }
    }
    footer{
      width: 100%;
      height: 59px;
      background: #fafafa;
      border-top: 1px solid #e5e5e5;
      position: absolute;
      right: 0;
      bottom: 0;
      display: flex;
      flex-direction: row;
      justify-content: center;
      .buttons{
        width: 93px;
        height: 37px;
        line-height: 39px;
        text-align: center;
        font-size: 16px;
        margin: auto 0;
        cursor: pointer;
      }
      .but1{
        background: #fff;
        color: #666666;
        border: 1px solid #dddddd;
        margin-right: 10px;
      }
      .but2{
        background: #0f76c8;
        color: #fff;
        border: 1px solid #0f76c8;
      }
    }
  }
</style>
